<?php if(!defined('HOST'))die('not access');?>
<div>
    <b style="font-size:20px">设置UKey是否开启：</b>
    <input style="margin-right: 5px;" name="status" type="checkbox">
</div>
<script>
    var sta = false;
    $.ajax({
        url: "./index.php?a=getSwitch&m=ukey&d=system&ajaxbool=true",
        async : false,
        success: function(obj){
            obj = JSON.parse(obj);
            if(obj.code == 200){
                var data = obj.data;
                if(data == 1) {
                    sta = true;
                }else {
                    sta = false;
                }
            }
        }
    });

    $('[name="status"]').bootstrapSwitch({    //初始化按钮
        state:sta,
        onText:"已开启",
        offText:"已关闭",
        onColor:"success",
        offColor:"info",// 设置OFF文本颜色 (info/success/warning/danger/primary)
        size:"normal",// 设置控件大小,从小到大  (mini/small/normal/large)
        onSwitchChange:function(event,state){
            if(state==true){
                switchs = 1;
            }else{
                switchs = -1;
            }
            $.ajax({
                url: "./index.php?a=switch&m=ukey&d=system&ajaxbool=true",
                data: {switchs: switchs},
                success: function(obj){
                    obj = JSON.parse(obj);
                    if(obj.code == 200){
                        layer.msg('修改成功');
                    }else{
                        layer.msg('修改失败');
                    }
                }
            });
        }
    });
</script>
